package com.wu.yygh.common.exception;

/**
 * @ClassName YyghException
 * @Author 浮生光
 * @Date 2022/6/29 22:57
 * @Description YyghException
 * @Version 1.0
 */
import com.wu.yygh.common.result.ResultCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("自定义全局异常类") //apiModel是描述返回对象的意义
public class YyghException extends RuntimeException{

    @ApiModelProperty("异常状态码")
    private Integer code;

    /**
     * 通过状态码和错误消息创建异常对象
     */
    public YyghException(String message, Integer code) {
        super(message);
        this.code = code;
    }

    /**
     * 接收枚举对象，里面也有对应的状态码和返回消息
     */
    public YyghException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    @Override
    public String toString() {
        return "YyghException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }
}